//see README here: https://github.com/ColinLeung-NiloCat/UnityURP-MobileScreenSpacePlanarReflection
#ifndef SSPRInclude
#define SSPRInclude

#pragma multi_compile _ _SSPR

#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl"

//textures
TEXTURE2D(_ReflectColor);
sampler LinearClampSampler;

struct ReflectionInput
{
    float3 posWS;
    float2 screenUV;
    float2 screenSpaceNoise;
    float roughness;
    float SSPR_Usage;
};
half3 GetResultReflection(ReflectionInput data) 
{ 
    //sample scene's reflection probe
    half3 viewWS = (data.posWS - GetAbsolutePositionWS(_WorldSpaceCameraPos));
    viewWS = normalize(viewWS);

    half3 reflectDirWS = viewWS * half3(1,-1,1);//reflect at horizontal plane

    //call this function in Lighting.hlsl-> half3 GlossyEnvironmentReflection(half3 reflectVector, half perceptualRoughness, half occlusion)
    //half3 reflectionProbeResult = GlossyEnvironmentReflection(reflectDirWS,data.roughness,1);               
    half4 SSPRResult = 0;

    SSPRResult = SAMPLE_TEXTURE2D(_ReflectColor, LinearClampSampler, data.screenUV + data.screenSpaceNoise); //use LinearClampSampler to make it blurry


    //final reflection
	half3 finalReflection = SSPRResult.rgb; //combine reflection probe and SSPR

	return finalReflection;
}
#endif
